﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BTKERP.Model;
using BTKERP.BLL.Inventory;

namespace BTKERP.MVCWeb.Controllers
{
    public class ShelfController : RestrictController
    {
        //
        // GET: /Shelf/

        public ActionResult Index()
        {
            List<Shelf> shelfs = InventoryInfoMgt.GetShelves();
            return View(shelfs);
        }

        //
        // GET: /Shelf/Details/5

        public ActionResult Details(int id)
        {

            return View();
        }

        //
        // GET: /Shelf/Create

        public ActionResult Create()
        {
            Shelf shelf = new Shelf();
            ViewData["WarehouseList"] = GetWarehouseSelectList();
            return View(shelf);
        } 

        //
        // POST: /Shelf/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                Shelf shelf = new Shelf();
                UpdateModel(shelf);
                InventoryInfoMgt.AddShelf(shelf.Code, shelf.Barcode, shelf.Name, shelf.Description, shelf.WarehouseId, shelf.Levels,
                    shelf.Capacity, shelf.Weight, shelf.Length, shelf.Width, shelf.Height, shelf.Thickness, SessionEntity.Staff.UserName);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Shelf/Edit/5
 
        public ActionResult Edit(Guid id)
        {
            Shelf shelf = InventoryInfoMgt.GetShelfById(id);
            ViewData["WarehouseList"] = GetWarehouseSelectList();
            return View(shelf);
        }

        //
        // POST: /Shelf/Edit/5

        [HttpPost]
        public ActionResult Edit(FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                Shelf shelf = new Shelf();
                UpdateModel(shelf);
                InventoryInfoMgt.UpdateShelf(shelf.Id, shelf.Code, shelf.Barcode, shelf.Name, shelf.Description, shelf.WarehouseId, shelf.Levels,
                    shelf.Capacity, shelf.Weight, shelf.Length, shelf.Width, shelf.Height, shelf.Thickness, SessionEntity.Staff.UserName);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Shelf/Delete/5
 
        public ActionResult Delete(Guid id)
        {
            Shelf shelf = InventoryInfoMgt.GetShelfById(id);
            return View(shelf);
        }

        //
        // POST: /Shelf/Delete/5

        [HttpPost]
        public ActionResult Delete(Shelf shelf)
        {
            try
            {
                // TODO: Add delete logic here
                InventoryInfoMgt.DeleteShelf(shelf.Id);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
